package cn.wolfcode.crm.web.controller;


import cn.wolfcode.crm.domain.CustomerTransfer;
import cn.wolfcode.crm.domain.Employee;
import cn.wolfcode.crm.query.CustomerTransferQueryObject;
import cn.wolfcode.crm.service.ICustomerTransferService;
import cn.wolfcode.crm.util.UserContext;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.subject.Subject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;

@RequestMapping("customerTransfer")
@Controller
public class CustomerTransferController {
    @Autowired
    private ICustomerTransferService customerTransferService;

    @RequestMapping("list")
    public String list(Model model,@ModelAttribute("qo") CustomerTransferQueryObject qo) {
        Subject subject = SecurityUtils.getSubject();
        if (!(subject.hasRole("admin")||subject.hasRole("客户经理"))){
            Employee currentUser = UserContext.getCurrentUser();
            qo.setSellerId(currentUser.getId());
        }
        model.addAttribute("pageInfo", customerTransferService.queryForList(qo));
        return "customerTransfer/list";
    }

    @RequestMapping("save")
    public String save(CustomerTransfer entity) {
        customerTransferService.save(entity);
        return "redirect:/customerTransfer/list.do";
    }
}
